package com.atguigu.gmall.common.util;

import com.atguigu.gmall.model.to.UserAuthTo;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @Author 卡尼奶
 * @Date 2022/6/1 21:17
 * @Version 1.0
 */
public class AuthUtil {
    public static UserAuthTo getUserAuth(){
        ServletRequestAttributes request = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String userId = request.getRequest().getHeader("UserId");
        String userTempId = request.getRequest().getHeader("UserTempId");
        UserAuthTo userAuthTo = new UserAuthTo();
        if (!StringUtils.isEmpty(userId)){
            userAuthTo.setUserId(Long.valueOf(userId));
        }

        if (!StringUtils.isEmpty(userTempId)){
            userAuthTo.setUserTempId(userTempId);
        }

        return userAuthTo;
    }
}
